package com.chy.blog_server.core.adapter;

import com.chy.blog_server.core.util.UploadURLUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 路径映射适配器
 */
@Configuration
public class URLMappingAdapter implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        /**
         * 资源映射路径
         * addResourceHandler：访问映射路径
         * addResourceLocations：资源绝对路径
         */
        //头像映射路径
        registry.addResourceHandler("/" + UploadURLUtil.HEAD_PHOTO_PATH + "/**")
                .addResourceLocations("file:" + UploadURLUtil.HEAD_PHOTO);

        //内容图片映射路径
        registry.addResourceHandler("/" + UploadURLUtil.CONTENT_IMAGE_PATH + "/**")
                .addResourceLocations("file:" + UploadURLUtil.CONTENT_IMAGE);

        //相册封面图映射路径
        registry.addResourceHandler("/" + UploadURLUtil.PHOTO_ALBUM_IMG_PATH + "/**")
                .addResourceLocations("file:" + UploadURLUtil.PHOTO_ALBUM_IMG);

        //照片映射路径
        registry.addResourceHandler("/" + UploadURLUtil.PHOTO_IMG_PATH + "/**")
                .addResourceLocations("file:" + UploadURLUtil.PHOTO_IMG);

        //文章图片映射路径
        registry.addResourceHandler("/" + UploadURLUtil.ARTICLE_IMAGE_PATH + "/**")
                .addResourceLocations("file:" + UploadURLUtil.ARTICLE_IMAGE);

        //游客发布文章图片映射路径
        registry.addResourceHandler("/" + UploadURLUtil.U_ARTICLE_IMAGE_PATH + "/**")
                .addResourceLocations("file:" + UploadURLUtil.U_ARTICLE_IMAGE);

        //个人日记图片映射路径
        registry.addResourceHandler("/" + UploadURLUtil.PERSONAL_DIARY_IMAGE_PATH + "/**")
                .addResourceLocations("file:" + UploadURLUtil.PERSONAL_DIARY_IMAGE);

        //首页展示照片映射路径
        registry.addResourceHandler("/" + UploadURLUtil.INDEX_IMAGE_PATH + "/**")
                .addResourceLocations("file:" + UploadURLUtil.INDEX_IMAGE);

        //音乐映射路径
        registry.addResourceHandler("/" + UploadURLUtil.MUSIC_PATH + "/**")
                .addResourceLocations("file:" + UploadURLUtil.MUSIC);

        //附件映射路径
        registry.addResourceHandler("/" + UploadURLUtil.FILE_PATH + "/**")
                .addResourceLocations("file:" + UploadURLUtil.FILE);

        //动态图片映射路径
        registry.addResourceHandler("/" + UploadURLUtil.DYNAMIC_PATH + "/**")
                .addResourceLocations("file:" + UploadURLUtil.DYNAMIC);

    }

}
